package com.st.lotte.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.st.lotte.model.Code;
import com.st.lotte.model.TLO_DELY_TRCE_RECV_IF;
import com.st.lotte.util.DBUtil;
import com.st.lotte.util.Database;
import com.st.lotte.util.LogTrace;

public class LateDAO {
private static final Logger log = LoggerFactory.getLogger(LateDAO.class);
	
	Connection conn = null;
	Database db = new Database();
	
	public LateDAO(){
		conn = db.getConnection();
	}
	
	protected synchronized void finalize() throws Throwable {
		conn.close();
	}; 
	
	/*
	 * 롯데 지연관련 쿼리문 실행 
	 * */
	// 24시간이상 - 48이하시간 지연
	public synchronized TLO_DELY_TRCE_RECV_IF findByDelayOneTwo(String date) {
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		TLO_DELY_TRCE_RECV_IF dto = null;
		Vector<Code> list = new Vector<Code>();
		try {
			String sql = DBUtil.DELAY_ONETWO;
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, date);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				dto = new TLO_DELY_TRCE_RECV_IF();
				dto.setRECV_DATE(rs.getDate("RECV_DATE"));
				dto.setCNT(rs.getInt("count"));
				System.out.println("dto= "+ dto.getRECV_DATE() + "//" + dto.getCNT());
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		LogTrace.TraceLog("[code dao] 24-48 Complete!!");
		
		return dto;
	}
	
	// 48시간초과 - 72시간이하시간 지연
	public synchronized TLO_DELY_TRCE_RECV_IF findByDelayTwoThree(String date) {
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		TLO_DELY_TRCE_RECV_IF dto = null;
		Vector<Code> list = new Vector<Code>();
		try {
			String sql = DBUtil.DELAY_TWOTHREE;
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, date);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				dto = new TLO_DELY_TRCE_RECV_IF();
				dto.setRECV_DATE(rs.getDate("RECV_DATE"));
				dto.setCNT(rs.getInt("count"));
				System.out.println("dto= "+ dto.getRECV_DATE() + "//" + dto.getCNT());
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		LogTrace.TraceLog("[code dao] 48-72 Complete!!");
		
		return dto;
	}
	
	// 72시간초과 
	public synchronized TLO_DELY_TRCE_RECV_IF findByDelayThreeOver(String date) {
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		TLO_DELY_TRCE_RECV_IF dto = null;
		Vector<Code> list = new Vector<Code>();
		try {
			String sql = DBUtil.DELAY_THREEOVER;
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, date);
			rs = pstmt.executeQuery();
			while (rs.next()) {
				dto = new TLO_DELY_TRCE_RECV_IF();
				dto.setRECV_DATE(rs.getDate("RECV_DATE"));
				dto.setCNT(rs.getInt("count"));
				System.out.println("dto= "+ dto.getRECV_DATE() + "//" + dto.getCNT());
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		LogTrace.TraceLog("[code dao] 72+ Complete!!");
		
		return dto;
	}	
}









